<template>
    <div>
        <div class="header">
            <div class="header-left">            
                <p class="title">账目清单</p>
                <p class="date">2024.8.01 ～ 2024.8.31</p>
            </div>

            <div class="header-right">
                总支出 
                <span class="total-pay">
                    -10.00
                </span>
                <span class="line"></span>
                总收入 
                <span class="total-income">
                    +10.00
                </span>
                <span class="line"></span>
                结余 
                <span class="leave">
                    0.00
                </span>
                <span class="unit">(单位: 元)</span>
            </div>
        </div>

        <el-divider />

        <div class="operate">
            <div>  
                <el-form :inline="true":model="formInline" class="demo-form-inline">
                    <el-form-item label="账户">
                        <el-input v-model="formInline.user" placeholder="查询账户" clearable />
                    </el-form-item>
                    <el-form-item label="时间">
                        <el-date-picker
                            v-model="formInline.date"
                            type="date"
                            placeholder="选择时间"
                            clearable
                        />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">查询</el-button>
                        <el-button type="primary" @click="dialogFormVisible = true">记一笔</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>

        <div class="content">
            <el-table :data="tableData" style="width: 100%">
                <el-table-column prop="date" label="日期" width="180" />
                <el-table-column prop="category" label="分类" width="180" />
                <el-table-column  label="金额" width="180">
                    <template #default="scope">
                        <div>
                            <span :style="scope.row.money > 0 ? 'color:red' : 'color:green'">{{ scope.row.money > 0 ? '+' + scope.row.money : scope.row.money }}</span>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="account" label="账户" />
                <el-table-column prop="remakes" label="备注" />
            </el-table>
            <div class="pagination">
                <el-pagination
                    size="small"
                    background
                    layout="prev, pager, next"
                    :total="50"
                    class="mt-4"
                />
            </div>
        </div>
    </div>

    <el-dialog v-model="dialogFormVisible" title="记一笔" width="500" center>
        <div class="write-one">
            <el-form :model="form">
                <el-form-item label="日期" label-width="auto">
                    <el-input v-model="form.name" autocomplete="off" />
                </el-form-item>
                <el-form-item label="分类" label-width="auto">
                    <el-input v-model="form.name" autocomplete="off" />
                </el-form-item>
                <el-form-item label="金额" label-width="auto">
                    <el-input v-model="form.name" autocomplete="off" />
                </el-form-item>
                <el-form-item label="账户" label-width="auto">
                    <el-input v-model="form.name" autocomplete="off" />
                </el-form-item>
                <el-form-item label="备注" label-width="auto">
                    <el-input v-model="form.name" autocomplete="off" />
                </el-form-item>
            </el-form>
        </div>
        <template #footer>
        <div class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取消</el-button>
            <el-button type="primary" @click="dialogFormVisible = false">确认</el-button>
        </div>
        </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'

const dialogFormVisible = ref(false)

const form = reactive({
  name: ''
})

const formInline = reactive({
  user: '',
  region: '',
  date: '',
})

const onSubmit = () => {
  console.log('submit!')
}

const tableData = [
  {
    date: '2016-05-03',
    category: '食物',
    money: -2000,
    account: '银行卡',
  },
  {
    date: '2016-05-02',
    category: '出行',
    money: 3000,
    account: '支付宝',
  },
]
</script>

<style lang="scss">
.header {
    display: flex;

    .header-left {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: start;

        .title {
            font-size: 18px;
            margin-right: 8px;
            font-weight: bolder;
            color: #312f2c;
        }

        .date {
            font-size: 13px;
            font-weight: bolder;
        }
    }

    .header-right {
        display: flex;
        align-items: center;

        .total-pay {
            padding-left: 8px;
            color: green;
        }

        .total-income {
            padding-left: 8px;
            color: red;
        }

        .leave {
            padding-left: 8px;
            color: gray;
        }

        .line {
            height: 12px;
            border-right: 1px solid #e7e7e7;
            margin: 0 12px;
        }

        .unit {
            padding-left: 12px;
            font-size: 12px;
            color: #aaa;
        }
    }
}

.operate {
    display: flex;
    align-items: center;
    padding: 10px 0;
    margin-bottom: 10px;
    padding-left: 15px;
    background-color: #F2F6FC;

    .el-form-item {
        margin-bottom: 0;
    }
}

.content {
    .pagination {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 15px;
    }
}

.write-one {
    padding: 0 50px;
}
</style>